#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-14 11:15 上午
# @Author  : yangdy
# @File    : 零矩阵
# @Software: PyCharmCE
from typing import List


class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        if not matrix:
            return
        n, m = len(matrix), len(matrix[0])
        for i in range(n):
            for j in range(m):
                flag = 1
                for k in range(m):
                    if matrix[i][k] == 0:
                        flag = 0
                for k in range(n):
                    if matrix[k][j] == 0:
                        flag = 0
                matrix[i][j] = matrix[i][j] * 10 + flag

        for i in range(n):
            for j in range(m):
                if matrix[i][j] % 10 == 0:
                    matrix[i][j] = 0
                else:
                    matrix[i][j] //= 10
        return


solve = Solution()

questions = [
    ([[1, 1, 1], [1, 0, 1], [1, 1, 1]], ),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    for qqi in q[0]:
        print(qqi)
    print('ans:', solve.setZeroes(q[0]))
    for qqi in q[0]:
        print(qqi)

